package com.kkb.service;

import com.kkb.mapper.UserMapper;
import com.kkb.pojo.User;
import com.kkb.pojo.UserExample;
import com.kkb.vo.LoginQueryVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserService {
    @Resource
    private UserMapper userMapper;

    @Transactional(propagation = Propagation.REQUIRED, readOnly = true)
    public int login(LoginQueryVO vo) {
        UserExample userExample = new UserExample();
        UserExample.Criteria criteria = userExample.createCriteria();
        if (vo != null) {
            if (vo.getUsername() != null) {
                criteria.andUsernameEqualTo(vo.getUsername());
            } else {
                return -1;
            }
        }
        List<User> users = userMapper.selectByExample(userExample);
        if (users == null || users.size() == 0) {
            return -1;
        } else {
            if (users.get(0).getPassword().equals(vo.getPassword().trim())) {
                if ("7236".equals(vo.getVerify().trim())) {
                    return 1;
                } else {
                    return -3;
                }
            } else {
                return -2;
            }
        }

    }
}
